import { POST } from '../axios.config.js'

const base = window.config.ip
const model = `${base}/rcdg-zbkh/ind-index-model`

const URLS = {
  listModel: `${model}/listModel`, // 获取模型列表
  delModel: `${model}/delModel`, // 删除模型
  saveModel: `${model}/saveModel`, // 保存模模型基本信息
  listModelIndex: `${model}/listModelIndex`, // 获取模型层级列表
  saveModelIndex: `${model}/saveModelIndex`, // 保存模型层级
  delModelIndex: `${model}/delModelIndex`, // 删除模型层级项（递归删除子级）
  delModelIndexOption: `${model}/delModelIndexOption`, // 删除指标选项
  getIndexOptionDetail: `${model}/getIndexOptionDetail`, // 获取指标选项详情
  saveIndexOption: `${model}/saveIndexOption`, // 保存指标选项
  updateIndexOptionStatus: `${model}/updateIndexOptionStatus`, // 更新指标状态

  getShareScoreConfig: `${model}/getShareScoreConfig`, // 获取共享/效果分值考核配置项
  saveShareScoreRule: `${model}/saveShareScoreRule`, // 保存共享/效果分值考核配置项
  listDefaultModelIndex: `${model}/listDefaultModelIndex`, // 获取默认模型指标列表
}

// 获取模型列表
export const listModel = ({ id, modelName, status, type }, currentPage = 1, pageSize = 10) =>
  POST(URLS.listModel, {
    param: {
      id,
      modelName,
      status,
      type,
    },
    currentPage,
    pageSize,
  })

// 删除模型
export const delModel = id =>
  POST(URLS.delModel, {
    id,
  })

// 获取模型列表（单个）
export const getModelInfo = id =>
  POST(URLS.listModel, {
    param: {
      id,
    },
    currentPage: 1,
    pageSize: 1,
  })

// 新建模型
export const createIndModel = (modelName, type, codeNumberList) =>
  POST(URLS.saveModel, { modelName, type, codeNumberList, status: 0 })

// 编辑模型
export const editModel = (id, { modelName, status }) => POST(URLS.saveModel, { id, modelName, status })

// 获取模型层级列表
export const listModelLvlInfo = id => POST(URLS.listModelIndex, { id })

// 保存模型层级
export const saveModelLvlInfo = (modelId, { id, pid, indexName }) =>
  POST(URLS.saveModelIndex, { modelId, id, pid, indexName })

// 删除模型层级项（递归删除子级）
export const delModelLvlItem = id => POST(URLS.delModelIndex, { id })

// 删除指标选项
export const delModelIndItem = (modelId, codeNumber) => POST(URLS.delModelIndexOption, { modelId, codeNumber })

// 获取指标选项详情
export const getIndexOptionDetail = (modelId, codeNumber) => POST(URLS.getIndexOptionDetail, { modelId, codeNumber })

// 保存指标选项
export const saveIndexOption = (
  modelId,
  pid,
  { optionName, codeDesc, keyWord, optionDetailList, scoreDTO, shareScoreList, status },
  codeNumber
) =>
  POST(URLS.saveIndexOption, {
    modelId,
    indexId: pid,
    codeNumber,
    optionName,
    codeDesc,
    keyWord,
    optionDetailList,
    scoreDTO,
    shareScoreList,
    status,
  })

// 保存指标选项
export const updateIndexOptionStatus = (modelId, codeNumber, status) =>
  POST(URLS.updateIndexOptionStatus, {
    modelId,
    codeNumber,
    status: status,
  })

// 获取共享/效果分值考核配置项
export const getShareScoreConfig = id => POST(URLS.getShareScoreConfig, { id })

// // 保存共享/效果分值考核配置项
// export const saveShareScoreRule = (optionId, shareScoreList) =>
//   POST(URLS.saveShareScoreRule, { optionId, shareScoreList })

// 获取默认模型指标列表
export const listIndModelLib = indType =>
  POST(URLS.listDefaultModelIndex, {
    oneParam: indType,
  })
